package mobi.hami.huapin.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 *  http请求类
 *
 * @author 阿飞 jijunjian@hami.mobi
 * @date 2018/9/5 14:22
 */
@Component
public class RestTemplateHelper {

    private static final Logger logger = LoggerFactory.getLogger(RestTemplateHelper.class);

    private static final RestTemplate restTemplate = new RestTemplate();

    public String postForObject(String url ,String postDta)
    {
        HttpHeaders headers = new HttpHeaders();
        MediaType mediaType = MediaType.parseMediaType("application/json;charset=utf-8");
        headers.setContentType(mediaType);

        HttpEntity<String> formEntity = new HttpEntity<String>(postDta, headers);

        String responseEntity = restTemplate.postForObject(url, formEntity, String.class);

        return  responseEntity;
    }

    public String getForObject(String url )
    {
        String responseEntity = restTemplate.getForObject(url,  String.class);
        return  responseEntity;
    }


}
